﻿Public Class Frmemployee

    Private Sub Frmemployee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadtable("select * from employee_tbl")
        ComboBox1.DisplayMember = "emp_name"
        ComboBox1.ValueMember = "emp_id"
        ComboBox1.DataSource = TBL
        If TBL.Rows.Count > 0 Then
            showData(rowIndex)
        End If
    End Sub
    Sub showData(ByVal i As Integer) 
        txtname.Text = TBL.Rows(i).Item(2)
        txtdob.Text = CDate(TBL.Rows(i).Item(3)).ToString("ddd-dd-MMM-yyyy")
        txtpod.Text = TBL.Rows(i).Item(4)
        txtadr.Text = TBL.Rows(i).Item(5)
        txtphone.Text = TBL.Rows(i).Item(6)
        txtsex.Text = TBL.Rows(i).Item(7)
        txtpos.Text = TBL.Rows(i).Item(8)
    End Sub

    Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
        If rowIndex >= 0 Then
            rowIndex = rowIndex - 1
            If rowIndex >= 0 Then
                showData(rowIndex)
            Else : MessageBox.Show("ទិន្នន័យចាប់ផ្តើម")
                rowIndex = rowIndex + 1
                showData(rowIndex)
            End If
        End If
    End Sub

    Private Sub btnNex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNex.Click
        If rowIndex >= 0 Then
            rowIndex = rowIndex + 1
            If rowIndex < TBL.Rows.Count Then
                showData(rowIndex)
            Else : MessageBox.Show("ទិន្នន័យចុងក្រោយ")
                rowIndex = rowIndex - 1
                showData(rowIndex)
            End If
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'MsgBox(ComboBox1.DisplayMember)
        ' MsgBox(ComboBox1.SelectedValue)
        'rowIndex = (TBL.Rows.Count - 1) - ((TBL.Rows.Count - 1) - (ComboBox1.SelectedIndex))
        ' showData(ComboBox1.SelectedValue - 1)
        'showData(rowIndex)
        showData(ComboBox1.SelectedIndex)
        'MsgBox(rowIndex)
    End Sub
    
    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

    End Sub
End Class